<?php
session_start();
echo "<pre>Press F5";
class MyClass {
    //static variable
    static private $foo_static;
    //normal variable
    private $foo = null;

    static function getString_static() {
        return self::$foo_static;
    }

    static function setString_static($str) {
        self::$foo_static = $str;
    }

    function setString($str) {
        $this->foo = $str;
    }

    function getString() {
        return $this->foo;
    }

}
if (!isset($_SESSION['myObj'])) {
    $myObj = new MyClass();
    $myObj->setString_static("Will NOT be stored!!!");
    $myObj->setString("Will be stored");

    echo "Print content: \n";
    echo 'Normal Var: ' . $myObj->getString() . "\n";
    echo 'Static Var: ' . $myObj->getString_static();

    echo "\t\n\nNow serialize and unserialize object\n";
    $myObj = unserialize(serialize($myObj));

    echo "And print again..\n";
    echo 'Normal Var: ' . $myObj->getString() . "\n";
    echo 'Static Var: ' . $myObj->getString_static();

    //Store object in session
    $_SESSION['myObj'] = serialize($myObj);

} else {
    //if myobj was stored
    $myObj_loaded = unserialize($_SESSION['myObj']);

    echo "Print content when serialized, stored in session and unserialized after a relaod:\n";
    echo 'Normal Var: ' . $myObj_loaded->getString() . "\n";
    echo 'Static Var: ' . $myObj_loaded->getString_static();

    unset($_SESSION['myObj']);
}

?>